package com.usian.controller;


import com.jayway.jsonpath.Criteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
public class HelloWorld {

    @Autowired
    private MongoTemplate mongoTemplate;

    @GetMapping("inst")
    public void save(){
        for (int i = 0; i <20 ; i++) {
            ApComment apComment = new ApComment();
            apComment.setAuthorName("小王");
            apComment.setContent("上海是不错的城市");
            apComment.setLikes(i);
            mongoTemplate.save(apComment);
        }
    }
    @GetMapping("update")
    public String update(){
        ApComment apComment = mongoTemplate.findById("5fc2fc3fb60c9a039c44556e", ApComment.class);
        apComment.setLikes(55);
        mongoTemplate.save(apComment);
        System.out.println(apComment);
        return "66666";
    }
@GetMapping("list")
    public String getList(){
   // Query query = Query.query(Criteria.where("authorName").is("小王").and("likes").lt(10)).limit(5).with(Sort.by(Sort.Direction.DESC,"likes"));
    //List<ApComment> apComments = mongoTemplate.find(query, ApComment.class);
     return "66";
    }
@GetMapping("find")
    public void testDel(){
       /* mongoTemplate.remove(Query.query(Criteria.where("authorName").is("小王").and("likes").lt(10)),ApComment.class);*/
    }


    @RequestMapping("/demo")
   public String demo(){
        return "楠瓜";
    }
}

